<template>
  <div>
    <el-checkbox-group v-model="checkList">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">
        {{ item.name }}
      </el-checkbox>
    </el-checkbox-group>

    <div style="margin-top: 20px; text-align: right">
      <el-button type="primary" @click="hSubmit">确定</el-button>
      <el-button @click="closeDialog">取消</el-button>
    </div>
  </div>
</template>

<script>
import { getRoles } from '@/api/settings'
import { getUserInfoByID } from '@/api/user'
import { assignRoles } from '@/api/employees'
export default {
  props: {
    id: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      list: [],
      checkList: []
    }
  },
  methods: {
    async loadPermissionList() {
      try {
        const { data } = await getRoles({ page: 1, pagesize: 100 })
        console.log(data.data.rows)
        this.list = data.data.rows
        const res = await getUserInfoByID(this.id)
        this.checkList = res.data.data.roleIds
      } catch (error) {
        console.log(error)
      }
    },
    async hSubmit() {
      const { data } = await assignRoles({ id: this.id, roleIds: this.checkList })
      console.log(data)
      this.$emit('close')
    },
    closeDialog() {
      this.$emit('close')
    }
  }
}
</script>

<style>
</style>
